﻿using Blog.System.Authorize;
using Blog.System.Swagger;
using Blog.System.TooklKits.Base;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.AspNetCore.Mvc;

namespace Blog.System.HttpApi.Controllers
{
    [ApiController]
    [AllowAnonymous]
    [Route("[controller]")]
    [ApiExplorerSettings(GroupName = Grouping.GroupName_V4)]
    public class AuthController : AbpController
    {
        private readonly IAuthorizeService _authorizeService;

        public AuthController(IAuthorizeService authorizeService) 
        {
            _authorizeService = authorizeService;
        }
        
        /// <summary>
        /// 获取登录地址
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("url")]
        public async Task<ServiceResult<string>> GetLoginAddressAsnyc() 
        {
            return await _authorizeService.GetLoginAddressAsync();
        }

        /// <summary>
        /// 获取AccessToken
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("access_token")]
        public async Task<ServiceResult<string>> GetAccessTokenAsync(string code) 
        {
            return await _authorizeService.GetAccessTokenAsync(code);
        }

        /// <summary>
        /// 因为Github调不通，所以用一个通用的来维护
        /// </summary>
        /// <returns></returns>
        [HttpGet,Route("GetAdminToken")]
        public ServiceResult GetAdminToken() 
        {
            return _authorizeService.GetAdminToken();
        }
    }
}
